package com.the_last.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.the_last.mapper.SysPermissionBusinessTypeMapper;
import com.the_last.pojo.po.SysPermissionBusinessType;
import com.the_last.service.ISysPermissionBusinessTypeService;
import com.the_last.utils.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 权限业务类型服务实现类
 */
@Service
@RequiredArgsConstructor
public class SysPermissionBusinessTypeServiceImpl extends ServiceImpl<SysPermissionBusinessTypeMapper, SysPermissionBusinessType>
        implements ISysPermissionBusinessTypeService {
    
    @Override
    public Result<List<SysPermissionBusinessType>> getAllPermissionBusinessTypes() {
        try {
            LambdaQueryWrapper<SysPermissionBusinessType> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SysPermissionBusinessType::getStatus, 1)
                    .eq(SysPermissionBusinessType::getDeleted, 0)
                    .orderByAsc(SysPermissionBusinessType::getSortOrder);
            
            List<SysPermissionBusinessType> businessTypes = list(queryWrapper);
            return Result.success(businessTypes);
        } catch (Exception e) {
            return Result.fail("获取权限业务类型列表失败: " + e.getMessage());
        }
    }
    
    @Override
    public Result<SysPermissionBusinessType> getPermissionBusinessTypeById(Long id) {
        try {
            SysPermissionBusinessType businessType = getById(id);
            if (businessType == null || businessType.getDeleted().equals(1)) {
                return Result.fail("权限业务类型不存在");
            }
            return Result.success(businessType);
        } catch (Exception e) {
            return Result.fail("获取权限业务类型详情失败: " + e.getMessage());
        }
    }
}